---
sidebar_position: 9
---

# Groq

import groqLogo from '/img/groqLogo.png';

# <img src={groqLogo} className="adaptive-logo-filter" width="46" style={{float: 'left', marginRight: '-4px', marginTop: '14px'}} /><span className="direct-service-title">roq</span>

Properties used to connect to [Groq](https://groq.com/).

### `groq` {#groq}

- Type: \{[`chat?: Chat`](#Chat), [`textToSpeech?: TextToSpeech`](#TextToSpeech)\}
- Default: _\{chat: true\}_

import ContainersKeyToggleChatFunction from '@site/src/components/table/containersKeyToggleChatFunction';
import ContainersKeyToggle from '@site/src/components/table/containersKeyToggle';
import ComponentContainer from '@site/src/components/table/componentContainer';
import DeepChatBrowser from '@site/src/components/table/deepChatBrowser';
import LineBreak from '@site/src/components/markdown/lineBreak';
import BrowserOnly from '@docusaurus/BrowserOnly';
import TabItem from '@theme/TabItem';
import Tabs from '@theme/Tabs';

<BrowserOnly>{() => require('@site/src/components/nav/autoNavToggle').readdAutoNavShadowToggle()}</BrowserOnly>

## Service Types

### `Chat` {#Chat}

- Type: `true` | \{<br />
  &nbsp;&nbsp;&nbsp;&nbsp; `model?: string`, <br />
  &nbsp;&nbsp;&nbsp;&nbsp; `system_prompt?: string`, <br />
  &nbsp;&nbsp;&nbsp;&nbsp; `max_completion_tokens?: number`, <br />
  &nbsp;&nbsp;&nbsp;&nbsp; `temperature?: number`, <br />
  &nbsp;&nbsp;&nbsp;&nbsp; `top_p?: number`, <br />
  &nbsp;&nbsp;&nbsp;&nbsp; `stop?: string[]`, <br />
  &nbsp;&nbsp;&nbsp;&nbsp; `seed?: number`, <br />
  &nbsp;&nbsp;&nbsp;&nbsp; `tools?: object[]`, <br />
  &nbsp;&nbsp;&nbsp;&nbsp; `tool_choice?: 'none' | 'auto' | 'required' | {type: 'function'; function: {name: string}}`, <br />
  &nbsp;&nbsp;&nbsp;&nbsp; [`function_handler?: FunctionHandler`](#FunctionHandler), <br />
  &nbsp;&nbsp;&nbsp;&nbsp; `parallel_tool_calls?: boolean` <br />
  \}
- Default: _\{model: "llama-3.3-70b-versatile"\}_

Connect to Groq's [`chat/completions`](https://console.groq.com/docs/api-reference#chat-create) API. You can set this property to _true_ or configure it using an object: <br />
`model` is the name of the Groq model to be used by the API. Check [available models](https://console.groq.com/docs/models) for more. <br />
`system_prompt` provides behavioral context and instructions to the model. <br />
`max_completion_tokens` limits the maximum number of tokens in the generated response. <br />
`temperature` controls the randomness/creativity of responses (0.0-2.0). Higher values produce more diverse outputs. <br />
`top_p` controls diversity through nucleus sampling (0.0-1.0). <br />
`stop` are strings that will cause generation to stop when encountered. <br />
`seed` ensures deterministic outputs for the same input when set. <br />
`tools` array of function definitions that the model can call. <br />
`tool_choice` controls how the model uses tools - 'auto' lets model decide, 'none' disables tools, 'required' forces tool use. <br />
[`function_handler`](#FunctionHandler) enables function calling capabilities for tool use. <br />
`parallel_tool_calls` enables the model to call multiple tools simultaneously in one response. <br />

#### Example

<ContainersKeyToggle>
  <ComponentContainer>
    <DeepChatBrowser
      style={{borderRadius: '8px'}}
      directConnection={{
        groq: {
          key: 'placeholder key',
          chat: {system_prompt: 'You are a helpful assistant.', temperature: 0.7},
        },
      }}
    ></DeepChatBrowser>
  </ComponentContainer>
  <ComponentContainer>
    <DeepChatBrowser
      style={{borderRadius: '8px'}}
      directConnection={{
        groq: {
          chat: {system_prompt: 'You are a helpful assistant.', temperature: 0.7},
        },
      }}
    ></DeepChatBrowser>
  </ComponentContainer>
</ContainersKeyToggle>

<Tabs>
<TabItem value="js" label="Sample code">

```html
<deep-chat
  directConnection='{
    "groq": {
      "key": "placeholder key",
      "chat": {"system_prompt": "You are a helpful assistant.", "temperature": 0.7}
    }
  }'
></deep-chat>
```

</TabItem>
<TabItem value="py" label="Full code">

```html
<!-- This example is for Vanilla JS and should be tailored to your framework (see Examples) -->

<deep-chat
  directConnection='{
    "groq": {
      "key": "placeholder key",
      "chat": {"system_prompt": "You are a helpful assistant.", "temperature": 0.7}
    }
  }'
  style="border-radius: 8px"
></deep-chat>
```

</TabItem>
</Tabs>

<LineBreak></LineBreak>

:::info
Use [`stream`](/docs/connect#Stream) to stream the AI responses.
:::

<LineBreak></LineBreak>

#### Vision Example

Upload images alongside your text prompts for visual understanding. You must use a [model with vision capabilities](https://console.groq.com/docs/vision).

<ContainersKeyToggle>
  <ComponentContainer>
    <DeepChatBrowser
      style={{borderRadius: '8px'}}
      directConnection={{
        groq: {
          key: 'placeholder key',
          chat: {model: 'llama-3.2-11b-vision-preview'},
        },
      }}
      images={true}
      camera={true}
      textInput={{styles: {container: {width: '77%'}}}}
    ></DeepChatBrowser>
  </ComponentContainer>
  <ComponentContainer>
    <DeepChatBrowser
      style={{borderRadius: '8px'}}
      directConnection={{
        groq: {
          chat: {model: 'llama-3.2-11b-vision-preview'},
        },
      }}
      images={true}
      camera={true}
      textInput={{styles: {container: {width: '77%'}}}}
    ></DeepChatBrowser>
  </ComponentContainer>
</ContainersKeyToggle>

<Tabs>
<TabItem value="js" label="Sample code">

```html
<deep-chat
  directConnection='{
    "groq": {
      "key": "placeholder key",
      "chat": {"model": "llama-3.2-11b-vision-preview"}
    }
  }'
  images="true"
  camera="true"
></deep-chat>
```

</TabItem>
<TabItem value="py" label="Full code">

```html
<!-- This example is for Vanilla JS and should be tailored to your framework (see Examples) -->

<deep-chat
  directConnection='{
    "groq": {
      "key": "placeholder key",
      "chat": {"model": "llama-3.2-11b-vision-preview"}
    }
  }'
  images="true"
  camera="true"
  style="border-radius: 8px"
  textInput='{"styles": {"container": {"width": "77%"}}}'
></deep-chat>
```

</TabItem>
</Tabs>

<LineBreak></LineBreak>

:::tip
When sending images we advise you to set [`maxMessages`](/docs/connect#requestBodyLimits) to 1 to send less data and reduce costs.
:::

<LineBreak></LineBreak>

### `TextToSpeech` {#TextToSpeech}

- Type: `true` | \{<br />
  &nbsp;&nbsp;&nbsp;&nbsp; `model?: string`, <br />
  &nbsp;&nbsp;&nbsp;&nbsp; `voice?: string`, <br />
  &nbsp;&nbsp;&nbsp;&nbsp; `speed?: number`, <br />
  &nbsp;&nbsp;&nbsp;&nbsp; `response_format?: 'mp3' | 'opus' | 'aac' | 'flac'` <br />
  \}
- Default: _\{model: "playai-tts", voice: "Fritz-PlayAI", response_format: "mp3"\}_

Connect to Groq's [`audio/speech`](https://console.groq.com/docs/api-reference#audio-speechCalled) API. You can set this property to _true_ or configure it using an object: <br />
`model` is the name of the text-to-speech model. <br />
`voice` specifies the voice to use for speech synthesis. <br />
`speed` controls the playback speed of the generated audio (0.25-4.0). <br />
`response_format` specifies the audio format for the output. <br />

#### Example

<ContainersKeyToggle>
  <ComponentContainer>
    <DeepChatBrowser
      style={{borderRadius: '8px'}}
      directConnection={{
        groq: {
          key: 'placeholder key',
          textToSpeech: {voice: 'Fritz-PlayAI', speed: 1.2},
        },
      }}
    ></DeepChatBrowser>
  </ComponentContainer>
  <ComponentContainer>
    <DeepChatBrowser
      style={{borderRadius: '8px'}}
      directConnection={{
        groq: {
          textToSpeech: {voice: 'Fritz-PlayAI', speed: 1.2},
        },
      }}
    ></DeepChatBrowser>
  </ComponentContainer>
</ContainersKeyToggle>

<Tabs>
<TabItem value="js" label="Sample code">

```html
<deep-chat
  directConnection='{
    "groq": {
      "key": "placeholder key",
      "textToSpeech": {"voice": "Fritz-PlayAI", "speed": 1.2}
    }
  }'
></deep-chat>
```

</TabItem>
<TabItem value="py" label="Full code">

```html
<!-- This example is for Vanilla JS and should be tailored to your framework (see Examples) -->

<deep-chat
  directConnection='{
    "groq": {
      "key": "placeholder key",
      "textToSpeech": {"voice": "Fritz-PlayAI", "speed": 1.2}
    }
  }'
  style="border-radius: 8px"
></deep-chat>
```

</TabItem>
</Tabs>

<LineBreak></LineBreak>

## Tool Calling

Groq supports [function calling](https://console.groq.com/docs/tool-use) functionality:

### `FunctionHandler` {#FunctionHandler}

- Type: ([`functionsDetails: FunctionsDetails`](/docs/directConnection#FunctionsDetails)) => `{response: string}[]` | `{text: string}`

The actual function that the component will call if the model wants to use tools. <br />
[`functionsDetails`](/docs/directConnection#FunctionsDetails) contains information about what tool functions should be called. <br />
This function should either return an array of JSONs containing a `response` property for each tool function (in the same order as in [`functionsDetails`](/docs/directConnection#FunctionsDetails))
which will feed it back into the model to finalize a response, or return a JSON containing `text` which will immediately display it in the chat.

#### Example

<ContainersKeyToggleChatFunction service="groq"></ContainersKeyToggleChatFunction>

<Tabs>
<TabItem value="js" label="Sample code">

```js
// using JavaScript for a simplified example

chatElementRef.directConnection = {
  groq: {
    chat: {
      tools: [
        {
          type: 'function',
          function: {
            name: 'get_current_weather',
            description: 'Get the current weather in a given location',
            parameters: {
              type: 'object',
              properties: {
                location: {
                  type: 'string',
                  description: 'The city and state, e.g. San Francisco, CA',
                },
                unit: {type: 'string', enum: ['celsius', 'fahrenheit']},
              },
              required: ['location'],
            },
          },
        },
      ],
      function_handler: (functionsDetails) => {
        return functionsDetails.map((functionDetails) => {
          return {
            response: getCurrentWeather(functionDetails.arguments),
          };
        });
      },
    },
    key: 'placeholder-key',
  },
};
```

</TabItem>
<TabItem value="py" label="Full code">

```js
// using JavaScript for a simplified example

chatElementRef.directConnection = {
  groq: {
    chat: {
      tools: [
        {
          type: 'function',
          function: {
            name: 'get_current_weather',
            description: 'Get the current weather in a given location',
            parameters: {
              type: 'object',
              properties: {
                location: {
                  type: 'string',
                  description: 'The city and state, e.g. San Francisco, CA',
                },
                unit: {type: 'string', enum: ['celsius', 'fahrenheit']},
              },
              required: ['location'],
            },
          },
        },
      ],
      function_handler: (functionsDetails) => {
        return functionsDetails.map((functionDetails) => {
          return {
            response: getCurrentWeather(functionDetails.arguments),
          };
        });
      },
    },
    key: 'placeholder-key',
  },
};

function getCurrentWeather(location) {
  location = location.toLowerCase();
  if (location.includes('tokyo')) {
    return JSON.stringify({location, temperature: '10', unit: 'celsius'});
  } else if (location.includes('san francisco')) {
    return JSON.stringify({location, temperature: '72', unit: 'fahrenheit'});
  } else {
    return JSON.stringify({location, temperature: '22', unit: 'celsius'});
  }
}
```

</TabItem>
</Tabs>

<LineBreak></LineBreak>
